package com.example.wendao.common;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class AsyncExecutor<T> {

    public AsyncExecutor(){}

    private static int CORE_POOL_SIZE = 10;

    private static ExecutorService CACHED_THREAD_POOL = Executors.newCachedThreadPool();

    private static ExecutorService SCHEDULE_THREAD_POOL = Executors.newScheduledThreadPool(CORE_POOL_SIZE);

    private static ExecutorService SINGLE_THREAD_EXECUTOR = Executors.newSingleThreadExecutor();

    private static ExecutorService service = SINGLE_THREAD_EXECUTOR;

    public T submit(Callable<T> callable) {
        Future<T> f = service.submit(callable);
        try {
            return f.get();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public void execute(Runnable runnable){
        service.execute(runnable);
    }

}

